package leetcode_字符串._07数字与字符串间转换;

/**
 * 复数乘法
 * 1+1i  -2+-1i
 */
public class _537 {
    public static void main(String[] args) {
        //"78+-76i"
        //"-86+72i"
        System.out.println(complexNumberMultiply("78+-76i", "-86+72i"));
    }

    public static String complexNumberMultiply(String a, String b) {
        String[] split_a = a.split("\\+|i");
        String[] split_b = b.split("\\+|i");
        int x1 = Integer.parseInt(split_a[0]);
        int y1 = Integer.parseInt(split_a[1]);
        int x2 = Integer.parseInt(split_b[0]);
        int y2 = Integer.parseInt(split_b[1]);
        return (x1 * x2 - y1 * y2) + "+" + (x1 * y2 + x2 * y1) + "i";
    }

    public static String complexNumberMultiply_two(String a, String b) {
        String[] split_a = a.split("\\+");
        String[] split_b = b.split("\\+");
        int x1 = Integer.parseInt(split_a[0]);
        int y1 = Integer.parseInt(split_a[1].substring(0, split_a[1].length() - 1));
        int x2 = Integer.parseInt(split_b[0]);
        int y2 = Integer.parseInt(split_b[1].substring(0, split_b[1].length() - 1));
        int x = x1 * x2 - y1 * y2;
        int y = x1 * y2 + x2 * y1;
        return x + "+" + y + "i";
    }

}
